<template>
  <view
    class="uni-calendar-item__weeks-box"
    :class="{
      'uni-calendar-item--disable': weeks.disable,
      'uni-calendar-item--isDay': calendar.fullDate === weeks.fullDate && weeks.isDay,
      'uni-calendar-item--checked':
        !weeks.disable && calendar.fullDate === weeks.fullDate && !weeks.isDay,
      'uni-calendar-item--before-checked': weeks.beforeMultiple,
      'uni-calendar-item--multiple': weeks.multiple,
      'uni-calendar-item--after-checked': weeks.afterMultiple
    }"
    :style="{backgroundColor: (calendar.fullDate === weeks.fullDate && weeks.isDay) || (!weeks.disable && calendar.fullDate === weeks.fullDate && !weeks.isDay) ? checkedBackground : 'none' }"
    @click="choiceDate(weeks)"
  >
    <view v-if="weeks.multiple" class="uni-calendar-item__weeks-box-item-bg--multiple"></view>
    <view class="uni-calendar-item__weeks-box-item">
      <view class="uni-calendar-item__weeks-box-item-inner">
        <text v-if="selected && weeks.extraInfo" class="uni-calendar-item__weeks-box-circle"></text>
        <text
          v-if="!lunar && !weeks.extraInfo && weeks.isDay"
          class="uni-calendar-item__weeks-lunar-text"
          :class="{
            'uni-calendar-item--isDay-text': !weeks.disable && weeks.isDay,
            'uni-calendar-item--isDay': calendar.fullDate === weeks.fullDate && weeks.isDay,
            'uni-calendar-item--checked':
              !weeks.disable && calendar.fullDate === weeks.fullDate && !weeks.isDay,
            'uni-calendar-item--before-checked': weeks.beforeMultiple,
            'uni-calendar-item--multiple': weeks.multiple,
            'uni-calendar-item--after-checked': weeks.afterMultiple,
            'uni-calendar-item--disable': weeks.disable
          }"
          :style="{backgroundColor: (calendar.fullDate === weeks.fullDate && weeks.isDay) || (!weeks.disable && calendar.fullDate === weeks.fullDate && !weeks.isDay) ? checkedBackground : 'none' }"
        >
          {{ todayText }}
        </text>
        <text
          class="uni-calendar-item__weeks-box-text"
          :class="{
            'uni-calendar-item--isDay-text': !weeks.disable && weeks.isDay,
            'uni-calendar-item--isDay': calendar.fullDate === weeks.fullDate && weeks.isDay,
            'uni-calendar-item--checked':
              !weeks.disable && calendar.fullDate === weeks.fullDate && !weeks.isDay,
            'uni-calendar-item--before-checked': weeks.beforeMultiple,
            'uni-calendar-item--multiple': weeks.multiple,
            'uni-calendar-item--after-checked': weeks.afterMultiple,
            'uni-calendar-item--disable': weeks.disable
          }"
          :style="{backgroundColor: (calendar.fullDate === weeks.fullDate && weeks.isDay) || (!weeks.disable && calendar.fullDate === weeks.fullDate && !weeks.isDay) ? checkedBackground : 'none' }"
        >
          {{ weeks.date }}
        </text>
        <text
          v-if="weeks.beforeMultiple"
          class="uni-calendar-item__weeks-lunar-text"
          :class="{
            'uni-calendar-item--multiple': weeks.multiple,
            'uni-calendar-item--before-checked': weeks.beforeMultiple
          }"
        >
          {{ beforeText }}
        </text>
        <text
          v-if="weeks.afterMultiple"
          class="uni-calendar-item__weeks-lunar-text"
          :class="{
            'uni-calendar-item--multiple': weeks.multiple,
            'uni-calendar-item--after-checked': weeks.afterMultiple
          }"
        >
          {{ afterText }}
        </text>
        <text
          v-if="lunar && !weeks.extraInfo"
          class="uni-calendar-item__weeks-lunar-text"
          :class="{
            'uni-calendar-item--isDay-text': !weeks.disable && weeks.isDay,
            'uni-calendar-item--isDay': calendar.fullDate === weeks.fullDate && weeks.isDay,
            'uni-calendar-item--checked': calendar.fullDate === weeks.fullDate && !weeks.isDay,
            'uni-calendar-item--before-checked': weeks.beforeMultiple,
            'uni-calendar-item--multiple': weeks.multiple,
            'uni-calendar-item--after-checked': weeks.afterMultiple,
            'uni-calendar-item--disable': weeks.disable
          }"
          :style="{backgroundColor: (calendar.fullDate === weeks.fullDate && weeks.isDay) || (!weeks.disable && calendar.fullDate === weeks.fullDate && !weeks.isDay) ? checkedBackground : 'none' }"
        >
          {{
            weeks.isDay
              ? todayText
              : weeks.lunar.IDayCn === '初一'
              ? weeks.lunar.IMonthCn
              : weeks.lunar.IDayCn
          }}
        </text>
        <text
          v-if="weeks.extraInfo && weeks.extraInfo.info"
          class="uni-calendar-item__weeks-lunar-text"
          :class="{
            'uni-calendar-item--extra': weeks.extraInfo.info,
            'uni-calendar-item--isDay-text': weeks.isDay,
            'uni-calendar-item--isDay': calendar.fullDate === weeks.fullDate && weeks.isDay,
            'uni-calendar-item--checked': calendar.fullDate === weeks.fullDate && !weeks.isDay,
            'uni-calendar-item--before-checked': weeks.beforeMultiple,
            'uni-calendar-item--multiple': weeks.multiple,
            'uni-calendar-item--after-checked': weeks.afterMultiple,
            'uni-calendar-item--disable': weeks.disable
          }"
        >
          {{ weeks.extraInfo.info }}
        </text>
      </view>
    </view>
  </view>
</template>

<script>

  export default {
    emits: ['change'],
    props: {
      weeks: {
        type: Object,
        default() {
          return {};
        }
      },
      calendar: {
        type: Object,
        default: () => {
          return {};
        }
      },
      selected: {
        type: Array,
        default: () => {
          return [];
        }
      },
      lunar: {
        type: Boolean,
        default: false
      },
      checkedBackground: {
        type: String,
        default: '#269c74'
      }
    },
    computed: {
      todayText() {
        return this.$t('uni-calender.today');
      },
      beforeText() {
        return this.$t('uni-calender.before');
      },
      afterText() {
        return this.$t('uni-calender.after');
      }
    },
    methods: {
      choiceDate(weeks) {
        this.$emit('change', weeks);
      }
    }
  };
</script>

<style lang="scss" scoped>
  $uni-font-size-base: 26rpx;
  $uni-text-color: #3d3d3d;
  $uni-font-size-sm: 20rpx;
  $uni-color-error: #269c74;
  $uni-opacity-disabled: 0.3;
  $uni-text-color-disable: #c0c0c0;
  $uni-primary: #269c74 !default;
  .uni-calendar-item__weeks-box {
    position: relative;
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100rpx;
    height: 100rpx;
  }

  .uni-calendar-item__weeks-box-item-bg--multiple {
    width: 100rpx;
    height: 100rpx;
    background-color: $uni-primary;
    opacity: 0.1;
  }

  .uni-calendar-item__weeks-box-text {
    font-size: $uni-font-size-base;
    color: $uni-text-color;
  }

  .uni-calendar-item__weeks-lunar-text {
    font-size: $uni-font-size-sm;
    color: $uni-text-color;
  }

  .uni-calendar-item__weeks-box-item {
    position: absolute;
    top: 0;
    left: 0;
    width: 100rpx;
    height: 100rpx;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .uni-calendar-item__weeks-box-item-inner {
    position: relative;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 92rpx;
    height: 92rpx;
  }

  .uni-calendar-item__weeks-box-circle {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 8px;
    height: 8px;
    border-radius: 8px;
    background-color: $uni-color-error;
  }

  .uni-calendar-item--disable {
    background-color: rgba(249, 249, 249, $uni-opacity-disabled);
    color: $uni-text-color-disable;
  }

  .uni-calendar-item--isDay-text {
    color: $uni-text-color;
  }

  .uni-calendar-item--isDay {
     background-color: $uni-primary;
    color: #fff;
    opacity: 1;
    border-radius: 6rpx;
  }

  .uni-calendar-item--extra {
    color: $uni-color-error;
    opacity: 0.8;
  }

  .uni-calendar-item--checked {
    background-color: $uni-primary;
    color: #fff;
    opacity: 1;
    border-radius: 6rpx;
  }

  .uni-calendar-item--multiple {
    color: $uni-text-color;
  }

  .uni-calendar-item--before-checked {
    background-color: $uni-primary;
    color: #fff;
    border-radius: 6rpx;
    opacity: 1;
  }

  .uni-calendar-item--after-checked {
    background-color: $uni-primary;
    color: #fff;
    border-radius: 6rpx;
    opacity: 1;
  }
</style>
